#include <iostream>
#include <queue>
#include <unordered_map>
using namespace std;

struct cmp{
	bool operator()(const int& p1,const int& p2){
		return p1>p2;
	}
};
int main() {

	string str;
	while(cin>>str){
		unordered_map<char,int> has;
		for(int i=0;i<static_cast<int>(str.size());++i){
			++has[str[i]];
		}
		priority_queue<int,vector<int>,cmp> q;
		for(auto& e:has){
			q.push(e.second);
		}
		int nRet=0;
		while(q.size()>=2){
			int u1=q.top();
			q.pop();
			int u2=q.top();
			q.pop();
			nRet+=u1+u2;
			q.push(u1+u2);
		}
		cout<<nRet<<endl;
	}
	
	return 0;
}
